// ShareUser.cpp: implementation of the CShareUser class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "phsshare.h"
#include "ShareUser.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CShareUser::CShareUser()
{

}

CShareUser::~CShareUser()
{

}


CString CShareUser::SelFile(CString DlgTitle, CString filter, int FilterInd, CString InitPath, bool CreatePrompt)
{
	CFileDialog fdg(TRUE);
	int i=0;
	char* lpszFilter=NULL;
	int len=filter.GetLength();
	lpszFilter=new char[len+2];
	memcpy(lpszFilter,(LPCTSTR)filter,len);
	lpszFilter[len]='\0';
	lpszFilter[len+1]='\0';
	i=0;
	while(lpszFilter[i]!='\0')
	{
		if(lpszFilter[i]=='|')
			lpszFilter[i]='\0';
		i++;
	}
	fdg.m_ofn.lpstrInitialDir=(LPCSTR)InitPath;
	fdg.m_ofn.lpstrFilter=lpszFilter;
	fdg.m_ofn.nFilterIndex=FilterInd;
	fdg.m_ofn.lpstrTitle=DlgTitle;
	if(CreatePrompt)
		fdg.m_ofn.Flags |= OFN_CREATEPROMPT;
	if(fdg.DoModal()==IDOK)
	{
		delete [] lpszFilter;
		return fdg.GetPathName();
	}
	delete [] lpszFilter;
	return "";
}

BOOL CShareUser::FileExists(CString filename)
{
	CFileStatus fileStatus;
	if(CFile::GetStatus(filename,fileStatus))
		return TRUE;
	return FALSE;
}

CString CShareUser::Trim(LPCTSTR pcs)
{
	CString s=pcs;
	s.TrimLeft();
	s.TrimRight();
	return s;
}
